package com.peanut.baby.mvp.profile.comments;

import android.app.Activity;

import com.peanut.baby.http.BaseObserver;
import com.peanut.baby.http.BaseScheduler;
import com.peanut.baby.http.RetrofitClient;
import com.peanut.baby.model.BBSComment;

import java.util.List;

import cn.nekocode.rxlifecycle.RxLifecycle;
import io.reactivex.Observable;

/**
 * Created by anonymouslystudio on 2017/8/22.
 */

public class ProfileCommentsPresenter implements ProfileCommentsContract.Presenter{
    private ProfileCommentsContract.View view;
    Activity activity;
    public ProfileCommentsPresenter(ProfileCommentsContract.View view,Activity activity) {
        this.view = view;
        this.activity = activity;
    }

    @Override
    public void getComments(String userId,int pageNo,int pageSize) {
        Observable obs = RetrofitClient.getInstance().getUserCommentedMoments(userId,
                pageNo,
                pageSize);
        obs.compose(BaseScheduler.<List<BBSComment>>compose())
                .compose(RxLifecycle.bind(activity).withObservable())
                .subscribe(new BaseObserver<List<BBSComment>>() {
            @Override
            protected void onHandleSuccess(List<BBSComment> o) {
                view.onGetCommentsSuccess(o);
            }

            @Override
            protected void onHandleError(String code,String msg) {
                view.onGetCommentsFailed(msg);
            }

        });

    }
}
